package com.autumn.xa.a.mq.demo;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: TestController
 *
 * @Description:
 * @Author: wangqiuyang
 * @Date: 2021/11/4 5:11 下午
 * History:
 * <author>          <time>          <version>          <desc>
 * wangqiuyang    2021/11/4 5:11 下午   @Version 1.0        描述
 */
@RestController
public class TestController {
    @Autowired
    private Producer producer;

    @GetMapping(value = "/test")
    public Object test(String msg) throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
        String str = "Hello World,My First RocketMQ Message=" + msg;
        Message message = new Message(RocketMQConfig.TOPIC, "tag1", str.getBytes());
        SendResult sendResult = producer.getProducer().send(message);
        System.out.println(sendResult);
        return sendResult.toString();
    }

    private static final String url = "https://enn-label.fat.ennew.com/api/queryLabelObjTreeByObjIdAndScope";

    public static void main(String[] args) {

        JSONObject json = new JSONObject();
        json.put("apiId","0004008001");
        json.put("labelObjId",4111);
        json.put("objId","10054226");
        json.put("orgCode","10000200");
        json.put("userId","10054226");
        json.put("userKey","6aee560f-71b3-4879-887b-f25fb98e7dba");

        String result= HttpUtil.createPost(url).body(json.toString()).execute().body();


        System.out.println(url);
        System.out.println(json.toString());
        System.out.println(result);
    }
}
